package com.common.utils.contract;

import java.io.UnsupportedEncodingException;

/**
 * base64工具
* @author 	zh
* @date 2018年1月25日
 */
public class BASE64Util {

	public static String decode(String str) {
	     String s=str;
	     String value = "";
		if(s==null){
			return "";
		}else{
			sun.misc.BASE64Decoder baseDecoder = new sun.misc.BASE64Decoder();
			try {
				value = new String(baseDecoder.decodeBuffer(s),"UTF-8");
				} catch (Exception ex) {
				}
			return value;
			}
		}
		
		public static String encode(String str) {
			String s=str;
			String value = "";
			if(s==null){
				return "";
			}else{
				try {
					value = new sun.misc.BASE64Encoder().encode(str.getBytes("utf-8"));
				} catch (UnsupportedEncodingException e) {
				}
				return value;
			}
		}
}
